package biz.noip.strategy.players.view;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.text.Text;
import org.andengine.util.color.Color;
import org.andengine.util.modifier.IModifier;
import org.andengine.util.modifier.ease.EaseSineIn;

import android.opengl.GLES20;
import biz.noip.strategy.activities.GameActivity;
import biz.noip.strategy.mediator.MediatorGame;
import biz.noip.strategy.players.Player;
import biz.noip.strategy.scenes.GameScene;
import biz.noip.strategy.util.ZIndex;

public class InfoView extends TextView {

	public InfoView(GameScene scene) {
		super(scene);
	}

	@Override
	public Text show(float x, float y) {
		final Text text = getText(x, y);
		text.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
		final Rectangle rect = new Rectangle(0, y - 10, GameActivity.CAMERA_WIDTH, 64, scene.vertexBufferObjectManager);
		rect.setColor(Color.RED);
		rect.setAlpha(0.9f);  
		rect.setZIndex(ZIndex.INFO_PANEL_CENTER.ordinal());
		text.setZIndex(ZIndex.TEXT_PANEL_CENTER.ordinal());
		scene.attachChild(rect);
		scene.attachChild(text);
		text.registerEntityModifier(new MoveModifier(5f, x - 100, x - 100 + 0.4f, y, y + 0.4f,
				new IEntityModifierListener() {

			public void onModifierStarted(IModifier<IEntity> arg0,
					IEntity arg1) {
				for (Player player : scene.getListPlayers()) {
					player.setSelectLock();
				}
			}

			public void onModifierFinished(IModifier<IEntity> arg0,
					IEntity arg1) {
				MediatorGame.getInstance().deleteChild(text, scene);
				MediatorGame.getInstance().deleteChild(rect, scene);
				for (Player player : scene.getListPlayers()) {
					player.setSelectUnlock();
				}
			}
		}, EaseSineIn.getInstance()));
		return text;
	}

}
